package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-03-10
 * Time:
 */
public class Test2 {

    public static void main(String[] args) {
        String str1 = "abc";
        String str2 = "bcd";
        String str3 = "BCD";

        //lastIndexOf():从后往前找

        System.out.println(str1.lastIndexOf('a'));//返回字符的下标(第一次出现)
        System.out.println(str1.indexOf('a',2));//从2下标开始从后往前

        System.out.println(str1.lastIndexOf("ab"));//在str1中找子串ab,返回下标
        System.out.println(str1.lastIndexOf("ab",2));//在str1中,从2下标开始从后往前找子串ab,返回下标

    }
    public static void main2(String[] args) {
        String str1 = "abc";
        String str2 = "bcd";
        String str3 = "BCD";

        char ch = str1.charAt(1);//charAt(int Index)输出某个位置(下标)的字符
        System.out.println(ch);

        System.out.println(str1.indexOf('a'));//返回字符的下标(第一次出现)
        System.out.println(str1.indexOf('a',2));//从2下标开始

        System.out.println(str1.indexOf("ab"));//在str1中找子串ab,返回下标
        System.out.println(str1.indexOf("ab",2));//在str1中,从2下标开始找子串ab,返回下标

    }

    public static void main1(String[] args) {
        String str1 = "abc";
        String str2 = "bcd";
        String str3 = "BCD";
        //compareTo比较字符串的大小,str1大于str2返回大于0的数...
        System.out.println(str1.compareTo(str2));
        //compareToIgnoreCase,区别是忽略大小写
        System.out.println(str3.compareToIgnoreCase(str3));
    }
}
